package com.deepinblog.jedisdemo;


import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class JedisDemoApplication {
    static JedisCluster jedisCluster;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7001));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7002));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7003));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7004));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7005));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7006));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7007));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7008));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7009));
        jedisClusterNode.add(new HostAndPort("10.211.55.7", 7010));
        jedisCluster = new JedisCluster(jedisClusterNode, config);
    }


    public static void main(String[] args) {


        String key = "name:008";


        set(key,"i am iron man");
        get(key);


    }

    public static void set(String key, String val) {
        jedisCluster.set(key, val);
        System.out.println("=========================Key:" + key + " set val :" + val + "=======================");
    }


    public static void get(String key) {
        String val = jedisCluster.get(key);
        System.out.println("=========================Val from redis :" + val + "=======================");
    }

}
